package cn.mw.cmdb.template.entity;

import cn.mw.cmdb.template.entity.convert.MwMonitorItemConvertDto;
import cn.mw.cmdb.template.enums.ZabbixMonitorTypeEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;

import java.util.List;

/**
 * 应用集
 */
@Getter
@Setter
@Schema(name = "MonitorItemDto", description = "监控项")
public class MonitorItemDto {

    @Schema(description = "监控项ID")
    private String itemId;

    @Schema(description = "监控项名称")
    private String name;

    @Schema(description = "键值")
    private String keyValue;

    @Schema(description = "间隔")
    private String delay;

    @Schema(description = "历史记录")
    private String history;

    @Schema(description = "趋势")
    private String trends;

    @Schema(description = "类型")
    private String type;

    @Schema(description = "状态")
    private String status;

    @Schema(description = "信息")
    private String information;

    @Schema(description = "触发器信息")
    private List<TriggerDto> triggers;

    public void extractFrom(MwMonitorItemConvertDto item){
        this.itemId = item.getItemid();
        this.name = item.getName();
        this.keyValue = item.getKey_();
        this.delay = item.getDelay();
        this.history = item.getHistory();
        this.trends = item.getTrends();
        ZabbixMonitorTypeEnum monitorTypeEnum = ZabbixMonitorTypeEnum.getMonitorTypeEnum(item.getType());
        if(monitorTypeEnum != null){
            this.type = monitorTypeEnum.getName();
        }
        this.status = item.getStatus();
    }
}
